package com.zyong.design.pattern.memento.case2;

/**
 * @program: zyong-design-pattern
 * @ClassName: TextDocument
 * @author: zyong
 * @create: 2024-05-12 22:35
 */
public class TextDocument {
    private String content;

    public TextDocument() {
        this.content = "";
    }

    public void setContent(String content) {
        this.content = content;
    }

    public String getContent() {
        return this.content;
    }

    /**
     * 创建备忘录，保存当前状态
     * @return
     */
    public Memento saveToMemento() {
        return new Memento(this.content);
    }

    /**
     * 恢复状态，从备忘录中恢复
     * @param memento
     */
    public void restoreFromMemento(Memento memento) {
        this.content = memento.getContent();
    }
}
